package Dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import Dao.Daomctwo;
import entity.mcone;
import entity.mctwo;
import utils.BaseDao;

public class Daoimplmctwo extends BaseDao implements Daomctwo {

	@Override
	public List<mctwo> mctwolist() {
		String sql = "select * from mctwo";
		ResultSet set = super.executeQuery(sql, null);
		List<mctwo> list = new ArrayList<mctwo>();
		try {
			while(set.next()){
				list.add(new mctwo(set.getInt(1),set.getString(2),set.getString(3),set.getInt(4)));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			super.closeAll(set, null, null);
		}
		return list;
	}

	@Override
	public List<mctwo> mctwolist(int spid) {
		String sql = "select * from mctwo where spid = ?";
		Object[] object = {spid};
		ResultSet set = super.executeQuery(sql, object);
		List<mctwo> list = new ArrayList<mctwo>();
		try {
			while(set.next()){
				list.add(new mctwo(set.getInt(1),set.getString(2),set.getString(3),set.getInt(4)));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			super.closeAll(set, null, null);
		}
		return list;
	}

	@Override
	public boolean add(mctwo mc) {
		String sql = "insert into `project`.`mctwo` (`name`, `img`, `spid`) values (?,?,?) ";
		Object[] object = {mc.getName(),mc.getImg(),mc.getSpid()};
		return super.executeUpdate(sql, object);
	}

	@Override
	public boolean del(int id) {
		String sql = "delete from `project`.`mctwo` where `id` = ? ";
		Object[] object = {id};
		return super.executeUpdate(sql, object);
	}

}
